//
// Created by wk on 2024/1/2.
//

#include "EncryptManager.h"
#include "EncryptTypeH265.h"
#include "EncryptDes.h"
#include "EncryptTypeXG.h"
#include "EncryptOther.h"

EncryptManager::EncryptManager() {
    mH265 = new EncryptTypeH265();
    mList.push_back(new EncryptTypeXG());
    mList.push_back(new EncryptTypeH265());
    mList.push_back(new EncryptDes());
    mList.push_back(new EncryptOther());
}

EncryptManager::~EncryptManager() {
    if (mH265) {
        delete mH265;
        mH265 = nullptr;
    }
}

bool EncryptManager::isH265(const std::string &src) {
    FILE *inputFile = fopen(src.c_str(), "rb");

    if (inputFile == nullptr)
        return false;
    AutoCloseFile input_file_close(inputFile);

    if (mH265->isEncryptType(inputFile))
        return true;

    return false;
}

int EncryptManager::getType(const std::string &src) {
    FILE *inputFile = fopen(src.c_str(), "rb");

    if (inputFile == nullptr)
        return false;
    AutoCloseFile input_file_close(inputFile);

    for (auto item: mList) {
        if (item->isEncryptType(inputFile)) {
            return item->getEncryptType();
        }
    }
    return 0;
}
